package io.gitee.zhangbinhub.admin.common

import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
import org.springframework.boot.autoconfigure.kafka.KafkaProperties
import org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration
import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import zipkin2.reporter.BytesMessageSender
import zipkin2.reporter.kafka.KafkaSender

/**
 * @since JDK 11
 */
@AutoConfiguration(before = [BusJacksonAutoConfiguration::class, ZipkinAutoConfiguration::class])
@RemoteApplicationEventScan(basePackageClasses = [AcpAdminComponentAutoConfiguration::class])
@Import(RedisAutoConfiguration::class)
class AcpAdminComponentAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(BytesMessageSender::class)
    fun zipkinKafkaSender(kafkaProperties: KafkaProperties): BytesMessageSender =
        KafkaSender.newBuilder().overrides(kafkaProperties.buildProducerProperties(null)).build()
}